<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png" />
    <HelloWorld msg="Welcome to Your Vue.js App" />
  </div>
</template>

<script>
import HelloWorld from "./components/HelloWorld.vue";
import store from "./store";
import { mapState, mapGetters, mapMutations, mapActions } from "vuex";

export default {
  name: "App",
  components: {
    HelloWorld,
  },
  created: function () {
    console.log(store);
    this.$store.dispatch("user/increment"); // 变更 +1
    console.log(store.state.user.count);

    // 查看状态
    console.log("-----state----");
    this.$store.commit("user/increment"); // 变更 +1
    console.log(store.state.user.count);

    console.log(this.count);
    this['user/incrementCount'](2)
    console.log(this.getcount);
    console.log(this.todos);

    //getters 计算属性
    console.log("-----getters----");
    console.log(this['user/doneTodos']);
    console.log(this['user/doneTodosCount']);

    // mutations 变更提交
    console.log("-----mutations----");
    // this.increment() // ==>this.$store.commit('increment')
    console.log(this.count);
    this['user/incrementCount'](10)
    console.log(this.getcount);

    // actions //异步的变更
    console.log("-----actions----");
    this['user/increment']()
    console.log(this.count);
    this['user/incrementObj']()
    console.log(this.count);
    this['user/checkout']({amount:4})
    console.log(this.getcount);

    // console.log(this["user/count"]);
    console.log(this.count);
    console.log(store.state.user.count);
  },
  computed: {
    ...mapState("user", ["count", "getcount", "todos"]),
    ...mapGetters([
      "user/doneTodos",
      "user/doneTodosCount",
      "user/getTodoById",
    ]),
  },
  methods: {
    ...mapMutations(["user/increment", "user/incrementCount"]),
    ...mapActions(["user/increment", "user/incrementObj", "user/checkout"]),
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
